(function () {

	function bind(curEle, eventType, evenFn) {
		if ('addEventListener' in document) {
			curEle.addEventListener(eventType, evenFn, false);
			return;
		}
		tempFn = function () {
			evenFn.call(curEle);
		};
		tempFn.photo = evenFn;

		if (!curEle['myBind' + eventType]) {
			curEle['myBind' + eventType] = [];
		}
		var ary = curEle['myBind' + eventType];

		for (var i = 0; i < ary.length; i++) {
			if (ary[i].photo === evenFn) {
				return;
			}
		}

		ary.push(tempFn);

		curEle.attachEvent('on' + eventType, tempFn);
	}

	function unbind(curEle, eventType, evenFn) {
		if ('removeEventListener' in document) {
			curEle.removeEventListener(eventType, evenFn, false);
			return;
		}
		var ary = curEle['myBind' + eventType];
		if (ary && ary instanceof Array) {
			for (var i = 0; i < ary.length; i++) {
				var cur = ary[i];
				if (cur.photo === evenFn) {
					ary.splice(i, 1);
					curEle.detachEvent('on' + eventType, cur);
					break;
				}
			}
		}
	}


	function on(curEle, eventType, evenFn) {
		if (!curEle['myEvent' + eventType]) {
			curEle['myEvent' + eventType] = [];
		}
		var ary = curEle['myEvent' + eventType];
		for (var i = 0; i < ary.length; i++) {
			if (ary[i] === evenFn) {
				return;
			}
		}
		ary.push(evenFn);

		bind(curEle, eventType, run);
	}


	function off(curEle, eventType, evenFn) {
		var ary = curEle['myEvent' + eventType];
		if (ary && ary instanceof Array) {
			for (var i = 0; i < ary.length; i++) {
				var cur = ary[i];
				if (cur === evenFn) {
					ary[i] = null;
					break;
				}
			}
		}
	}

	function run(e) {
		e = e || window.event;
		var flag = e.target ? true : false;
		if (!flag) {
			e.target = e.srcElement;
			e.pageX = e.clientX + (document.documentElement.scrollLeft || document.body.scrollLeft);
			e.pageY = e.clientY + (document.documentElement.scrollTop || document.body.scrollTop);
			e.preventDefault = function () {
				e.returnValue = false;
			};
			e.stopPropagation = function () {
				e.cancelBubble = true;
			}
		}

		var ary = this['myEvent' + e.type];
		for (var i = 0; i < ary.length; i++) {
			var tempFn = ary[i];
			if (typeof tempFn === 'function') {
				tempFn.call(this, e);
			} else {
				ary.splice(i, 1);
				i--;
			}
		}
	}

	window.icemanEvent = {
		on: on,
		off: off
	}

})();
